package com.datasecops.scannerservices.operation;

import org.openstack4j.api.OSClient;
import org.openstack4j.core.transport.HttpResponse;
import org.openstack4j.model.common.DLPayload;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.storage.object.SwiftObject;
import org.openstack4j.openstack.OSFactory;

import java.io.InputStream;
import java.util.List;

/** openStack数据库的操作
 * @author: GeXiaoLong
 * @time: 2022/11/21 11:46
 */
public class OpenStack {
    public static void mandate(){
//        Identifier domainIdentifier = Identifier.byName("Default");
//       OSClient.OSClientV3 os = OSFactory.builderV3()
//    git            .endpoint("http://10.26.18.101:5000/v3")
//                .credentials("admin", "openstack", domainIdentifier)
//                .authenticate();

        OSClient.OSClientV3 os= OSFactory.builderV3()
                .endpoint("http://10.26.18.101:5000/v3")
                .credentials("admin", "openstack", Identifier.byId("default"))
                .scopeToProject(Identifier.byName("admin"),Identifier.byId("default"))
                .authenticate();



        List<? extends SwiftObject> objs = os.objectStorage().objects().list("container1");
        SwiftObject remove = objs.remove(3);
        String name = remove.getName();
        System.out.println(name);

//        Map<String, String> md = os.objectStorage().objects().getMetadata("container1", name);
//        for (String s : md.keySet()) {
//            String s1 = md.get(s);
//            System.out.println(s1);
//        }
        DLPayload payload = os.objectStorage().objects().download("container1", name);
        HttpResponse httpResponse = payload.getHttpResponse();
        InputStream inputStream = payload.getInputStream();

    }


    public static void main(String[] args) {
        mandate();


    }
}
